<?php
declare(strict_types=1);

namespace LowCode\UI;

use LowCode\Block;
use LowCode\Node;

/**
 * @method static static make(string|null $mode = 'VNode' | 'Runtime' | 'Design' | 'Raw' | null);
 */
class JsonNode extends Node
{
    /**
     * @param string|null $mode 'VNode' | 'Runtime' | 'Design' | 'Raw'
     */
    public function __construct(string $mode = null)
    {
        parent::__construct();
        $mode && $this->mode($mode);
    }

    /**
     * @param string $mode
     * @return $this
     */
    public function mode(string $mode = 'VNode' | 'Runtime' | 'Design' | 'Raw'): static
    {
        return $this->prop("mode",$mode);
    }

    /**
     * @param string $url
     * @return $this
     */
    public function url(string $url): static
    {
        return $this->prop("url",$url);
    }

    /**
     * @param Block $schema
     * @return $this
     */
    public function schema(Block $schema): static
    {
        return $this->prop("schema",$schema);
    }

    /**
     * @param array $apis
     * @return $this
     */
    public function apis(array $apis): static
    {
        return $this->prop("apis",$apis);
    }

    /**
     * @param array $meta
     * @return $this
     */
    public function meta(array $meta): static
    {
        return $this->prop("meta",$meta);
    }

    /**
     * @param array $dependencies
     * @return $this
     */
    public function dependencies(array $dependencies): static
    {
        return $this->prop("dependencies",$dependencies);
    }

    /**
     * @param array $blocks
     * @return $this
     */
    public function blocks(array $blocks): static
    {
        return $this->prop("blocks",$blocks);
    }

    /**
     * @param array $globals
     * @return $this
     */
    public function globals(array $globals): static
    {
        return $this->prop("globals",$globals);
    }


    /**
     * @param bool $bool
     * @return $this
     */
    public function mock(bool $bool = true): static
    {
        return $this->prop("mock",$bool);
    }

    /**
     * @param array $assets ['css'=>[],'js'=>[],'script'=>[]]
     * @return $this
     */
    public function assets(array $assets = ['css'=>[],'js'=>[],'script'=>[]]): static
    {
        return $this->prop("assets",$assets);
    }

    /**
     * @param string $name
     * @param string $link
     * @return $this
     */
    private function makeAssets(string $name, string $link): static
    {
        $assets = $this->props['assets']??[];
        $option = $assets[$name]??[];
        $option[] = $link;
        $assets[$name] = $option;
        return $this->prop("assets",$assets);
    }

    /**
     * @param string $cssLink
     * @return $this
     */
    public function assetCss(string $cssLink): static
    {
        return $this->makeAssets("css",$cssLink);
    }

    /**
     * @param string $jsLink
     * @return $this
     */
    public function assetJs(string $jsLink): static
    {
        return $this->makeAssets("js",$jsLink);
    }

    /**
     * @param string $script
     * @return $this
     */
    public function assetScript(string $script): static
    {
        return $this->makeAssets("script",$script);
    }

}
